const app = getApp();
Component({
  properties: {
    showGetUserInfo: {
      type: Boolean,
      value: false
    }
  },
  data: {
    showGetUserInfo: false, //微信授权提示
    showSettingTip: false,  //打开授权设置
    showNoLoginTip: false, //拒绝微信授权，二次提示
    appLogo: "../../images/wxapp-logo.jpg"
  },
  methods: {
    //拒绝微信授权
    refuseGetInfo: function() {
      this.setData({
        showNoLoginTip: true,
        showGetUserInfo: false
      });
    },
    //获取用户信息
    bindGetUserInfo: function(e) {
      //console.log(e);
      /getUserInfo:fail/.test(e.detail.errMsg) ? this.setData({
        showSettingTip: true,
        showGetUserInfo: false,
        showNoLoginTip: false
      }) : (this.setData({
          showSettingTip: false,
          showGetUserInfo: false,
          showNoLoginTip: false
        }),
        app.sendUserInfo(e.detail.userInfo));
    },
    //打开设置
    openSetting: function() {
      var self = this;
      wx.openSetting({
        success: function(o) {
          true === o.authSetting["scope.userInfo"] && (app.requestUserWxInfo(), self.setData({
            showSettingTip: false,
            showNoLoginTip: false,
            showGetUserInfo: false
          }));
        }
      });
    },
    //打开设置
    buttonOpenSetting: function(e) {
      var self = this;
      true === e.detail.authSetting["scope.userInfo"] && (app.requestUserWxInfo(), self.setData({
        showSettingTip: false,
        showNoLoginTip: false,
        showGetUserInfo: false
      }));
    },
    //取消设置
    cancelSetting: function() {
      this.setData({
        showSettingTip: false,
        showNoLoginTip: true
      });
    },
    //拒绝登录 二次确认
    refuseLogin: function() {
      this.setData({
        showSettingTip: false,
        showGetUserInfo: false,
        showNoLoginTip: false
      })
    }
  }
});